package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcAndroidUpdate;
import com.visizen.wisdomclass.server.model.WcAndroidUpdateExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface WcAndroidUpdateMapper {

    //从更新数据库中获取最新的一条更新记录
    @Select("SELECT * FROM WC_ANDROID_UPDATE ORDER BY ID DESC LIMIT 1")
    WcAndroidUpdate getLastUpdate();

    @SelectProvider(type=WcAndroidUpdateSqlProvider.class, method="countByExample")
    int countByExample(WcAndroidUpdateExample example);

    @DeleteProvider(type=WcAndroidUpdateSqlProvider.class, method="deleteByExample")
    int deleteByExample(WcAndroidUpdateExample example);

    @Delete({
        "delete from wc_android_update",
        "where ID = #{ID,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long ID);

    @Insert({
        "insert into wc_android_update (ID, VER_CODE, ",
        "VERSION, VER_TIME, ",
        "CONTANT, ApkURL, ",
        "FORCES, TIMES)",
        "values (#{ID,jdbcType=BIGINT}, #{VER_CODE,jdbcType=VARCHAR}, ",
        "#{VERSION,jdbcType=VARCHAR}, #{VER_TIME,jdbcType=TIMESTAMP}, ",
        "#{CONTANT,jdbcType=VARCHAR}, #{apkURL,jdbcType=VARCHAR}, ",
        "#{FORCES,jdbcType=INTEGER}, #{TIMES,jdbcType=TIMESTAMP})"
    })
    int insert(WcAndroidUpdate record);

    @InsertProvider(type=WcAndroidUpdateSqlProvider.class, method="insertSelective")
    int insertSelective(WcAndroidUpdate record);

    @SelectProvider(type=WcAndroidUpdateSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="ID", property="ID", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="VER_CODE", property="VER_CODE", jdbcType=JdbcType.VARCHAR),
        @Result(column="VERSION", property="VERSION", jdbcType=JdbcType.VARCHAR),
        @Result(column="VER_TIME", property="VER_TIME", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CONTANT", property="CONTANT", jdbcType=JdbcType.VARCHAR),
        @Result(column="ApkURL", property="apkURL", jdbcType=JdbcType.VARCHAR),
        @Result(column="FORCES", property="FORCES", jdbcType=JdbcType.INTEGER),
        @Result(column="TIMES", property="TIMES", jdbcType=JdbcType.TIMESTAMP)
    })
    List<WcAndroidUpdate> selectByExample(WcAndroidUpdateExample example);

    @Select({
        "select",
        "ID, VER_CODE, VERSION, VER_TIME, CONTANT, ApkURL, FORCES, TIMES",
        "from wc_android_update",
        "where ID = #{ID,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="ID", property="ID", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="VER_CODE", property="VER_CODE", jdbcType=JdbcType.VARCHAR),
        @Result(column="VERSION", property="VERSION", jdbcType=JdbcType.VARCHAR),
        @Result(column="VER_TIME", property="VER_TIME", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CONTANT", property="CONTANT", jdbcType=JdbcType.VARCHAR),
        @Result(column="ApkURL", property="apkURL", jdbcType=JdbcType.VARCHAR),
        @Result(column="FORCES", property="FORCES", jdbcType=JdbcType.INTEGER),
        @Result(column="TIMES", property="TIMES", jdbcType=JdbcType.TIMESTAMP)
    })
    WcAndroidUpdate selectByPrimaryKey(Long ID);

    @UpdateProvider(type=WcAndroidUpdateSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcAndroidUpdate record, @Param("example") WcAndroidUpdateExample example);

    @UpdateProvider(type=WcAndroidUpdateSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") WcAndroidUpdate record, @Param("example") WcAndroidUpdateExample example);

    @UpdateProvider(type=WcAndroidUpdateSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcAndroidUpdate record);

    @Update({
        "update wc_android_update",
        "set VER_CODE = #{VER_CODE,jdbcType=VARCHAR},",
          "VERSION = #{VERSION,jdbcType=VARCHAR},",
          "VER_TIME = #{VER_TIME,jdbcType=TIMESTAMP},",
          "CONTANT = #{CONTANT,jdbcType=VARCHAR},",
          "ApkURL = #{apkURL,jdbcType=VARCHAR},",
          "FORCES = #{FORCES,jdbcType=INTEGER},",
          "TIMES = #{TIMES,jdbcType=TIMESTAMP}",
        "where ID = #{ID,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(WcAndroidUpdate record);
}